define(function(require, exports, module){
	var cloudProjectDetailTemp = require("text!../template/cloudProjectDetail.html");
	
	module.exports = Nuui.View.extend({
		
		template:cloudProjectDetailTemp,

		onRender:function(){
			var view = this;

            var project = App.storage.get('project');
            App.request(App.server.getServePath(App.path.cloudprojectAction), {
                //data:"",
                success:function(data){
                    if(data.ec){
                        alert(data.em);
                    }else {
                        var cloudProjectList = data.cloudProjectList;
                        for(var i = 0; i < cloudProjectList.length; i++){
                            var tpl= '';
                            tpl=' <div class="project-header" data-code="'+cloudProjectList[i].code+'">\n' +
                                '            <h1>'+cloudProjectList[i].title+'</h1>\n' +
                                '            <p><span>'+cloudProjectList[i].time+'</span><img src="../../../images/img/'+cloudProjectList[i].collect+'" alt="" class="img-collect"><span>'+cloudProjectList[i].classify+'</span></p>\n' +
                                '            <div class="img"><img src="../../../images/img/'+cloudProjectList[i].avatar+'" alt=""></div>\n' +
                                '        </div>'

                            if(cloudProjectList[i].code==project){
                                view.$(".cloudProjectDetail").html(tpl);
                            }
                        }


                        /**/
                        var tenderNotice = data.cloudProjectList[0];
                        var association = data.cloudProjectList[1];
                        /*console.log(tenderNotice)*/
                        var tpl1='<div class="tenderNotice">\n' +
                            '            <h3>一、招标情况</h3>\n' +
                            '            <ol>\n' +
                            '                <li>1、项目名称:'+tenderNotice.title+'</li>\n' +
                            '                <li>2、招标编号:'+tenderNotice.content.tenderReference+'</li>\n' +
                            '                <li>3、备案号:'+tenderNotice.content.AQ+'</li>\n' +
                            '                <li>\n' +
                            '                    4、项目信息：\n' +
                            '                    <ul>\n' +
                            '                        <li>项目编号：'+tenderNotice.content.itemNumber+'</li>\n' +
                            '                        <li>项目性质：'+tenderNotice.content.itemNature+'</li>\n' +
                            '                        <li>批准文号：'+tenderNotice.content.ApprovalNumber+'</li>\n' +
                            '                        <li>批准单位：'+tenderNotice.content.unit+'</li>\n' +
                            '                    </ul>\n' +
                            '                </li>\n' +
                            '                <li>\n' +
                            '                    5、标段信息：\n' +
                            '                    <ul>\n' +
                            '                        <li>标段编码：'+tenderNotice.content.blockCoding+'</li>\n' +
                            '                        <li>标段名称：'+tenderNotice.content.name+'</li>\n' +
                            '                        <li>投标文件截止时间：'+tenderNotice.content.deadline+'</li>\n' +
                            '                        <li>限价/元：详见招标文件</li>\n' +
                            '                    </ul>\n' +
                            '                </li>\n' +
                            '                <li>6、建设地点：'+tenderNotice.content.address+'</li>\n' +
                            '                <li>7、专业：'+tenderNotice.content.domain+'</li>\n' +
                            '                <li>8、招标种类：'+tenderNotice.content.kind+'</li>\n' +
                            '                <li>\n' +
                            '                    9、招标内容：\n' +
                            '                    <ul>\n' +
                            '                        <li>\n' +
                            '                            （1）项目概况\n' +
                            '                            <p>'+tenderNotice.content.projectOverview+'</p>\n' +
                            '                        </li>\n' +
                            '                        <li>\n' +
                            '                            （2）本次招标范围\n' +
                            '                            <p>'+tenderNotice.content.range+'</p>\n' +
                            '                            <p>计划工期：'+tenderNotice.content.plannedTime+'</p>\n' +
                            '                            <p>计划开工时间：'+tenderNotice.content.planStartTime+'</p>\n' +
                            '                            <p>计划竣工时间：'+tenderNotice.content.planEndTime+'</p>\n' +
                            '                        </li>\n' +
                            '                    </ul>\n' +
                            '                </li>\n' +
                            '            </ol>\n' +
                            '            <h3>二、工作时间</h3>\n' +
                            '            <ul>\n' +
                            '                <li>上午工作时间：'+tenderNotice.content.MorningHours+'</li>\n' +
                            '                <li>下午工作时间：'+tenderNotice.content.WorkingHours+'</li>\n' +
                            '            </ul>\n' +
                            '            <h3>三、报名</h3>\n' +
                            '            <ul>\n' +
                            '                <li>1、报名开始时间：'+tenderNotice.content.RegistrationTime+'</li>\n' +
                            '                <li>2、报名截止时间：'+tenderNotice.content.registrationDeadline+'</li>\n' +
                            '                <li>节假日：'+tenderNotice.content.Holidays+'</li>\n' +
                            '                <li>值班人员：'+tenderNotice.content.watchkeeper+'</li>\n' +
                            '                <li>手机：'+tenderNotice.content.phone+'</li>\n' +
                            '            </ul>\n' +
                            '        </div>\n' +
                            '    </div>';
                        var tpl2='<div>\n' +
                            '           <p>'+association.content.p1+'</p>\n' +
                            '           <p>'+association.content.p2+'</p>\n' +
                            '           <p>'+association.content.p3+'</p>\n' +
                            '           <p>'+association.content.p4+'</p>\n' +
                            '       </div>'
                        if(project=="tenderNotice"){
                            view.$(".content").html(tpl1);
                        }else if(project=="association"){
                            view.$(".content").html(tpl2);
                        }
                    }
                }
            });
        },
		onShow:function(){
            $(".cloudProjectDetail").on("tap",".img-collect",function () {
                if($(this).attr("src")=="../../../images/img/shoucang_1.png"){
                    $(this).attr("src","../../../images/img/yishoucang_1.png");
                    Nuui.utils.toast("收藏成功",{'title':''});
                    $(this).removeClass('active');
                }else {
                    $(this).attr("src","../../../images/img/shoucang_1.png");
                    Nuui.utils.toast("取消收藏",{'title':''});
                    $(this).addClass('active');
                }
            })
		}
		
	});	
});